package com.aliyun.heiyu.powermaster.server.rbac.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description 数据划分工具类
 * @Author shun.zhang
 * @Date 2020/10/26 16:35
 **/
public class SplitUtils {
    /**
     * 将大数据进行分批
     * @param list
     * @param split
     * @param <T>
     * @return
     */
    public static <T> List<List<T>> splitList(List<T> list, int split) {
        int end = 0;
        List<T> tempLst = null;
        List<List<T>> result = new ArrayList<>();
        for (int start = 0, size = list.size(); start < size; start += split) {
            end = start + split > size ? size : start + split;
            tempLst= list.subList(start, end);
            result.add(tempLst);
        }
        return result;
    }
}